package com.tensquare.friend.dao;
/*
 *ClassName:UserDao
 *Description:
 *@author:可爱的大鸭子
 */

import com.tensquare.friend.pojo.Gath;
import com.tensquare.friend.pojo.User;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Map;

public interface UserDao extends JpaRepository<User,String>,JpaSpecificationExecutor<User> {
    List<User> findAllByGatheringIsNotNullOrderByCreatetimeDesc();

    @Query(value = "select * from tb_user order by createtime desc limit 3",nativeQuery = true)
    List<User> findTop3ByTimeDesc();

    //限制在100我的推荐好友数目
    @Query(value = "select * from tb_user  where sex!=?2 and gathering!='' and id not in (select friendid from tb_friend where userid=?1) and id not in (select friendid from tb_nofriend where userid =?1)  limit 100",nativeQuery = true)
    List<User> getCommend(String uid,int sex);

    @Query(value = "select new com.tensquare.friend.pojo.Gath(t.gathering,count(t.gathering) as cnt) from User t where t.gathering is not null group by t.gathering order by cnt desc ")
    List<Gath> getHotGatherings();
}
